package edu.neusoft.android.yuejian14.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import java.util.List;

import edu.neusoft.android.yuejian14.Listener.RetrofitListener;
import edu.neusoft.android.yuejian14.R;
import edu.neusoft.android.yuejian14.adapter.VideoListAdapter;
import edu.neusoft.android.yuejian14.javabean.Video;
import edu.neusoft.android.yuejian14.model.VideoModel;

public class VideoListActivity extends BaseActivity implements View.OnClickListener,RetrofitListener {
    private RecyclerView recyclerView;
    private VideoListAdapter adapter;
    private TextView club_name,club_intro,club_course;
    private int clubid;
    private String clubName;


    @Override
    protected void initViews(){
        setLayout(R.layout.club_video_list);

        recyclerView =(RecyclerView)findViewById(R.id.home_recycler);
        club_name=(TextView) findViewById(R.id.cl_name);
        club_intro =(TextView) findViewById(R.id.cl_intro);
        club_intro.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(VideoListActivity.this,ClubIntroActivity.class);
                Bundle bundle= getIntent().getExtras();
                clubid=bundle.getInt("clubid");
                intent.putExtra("clubid",clubid);
                startActivity(intent);

            }
        });
        club_course =(TextView) findViewById(R.id.cl_class);
        club_course.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(VideoListActivity.this,CourseListActivity.class);
                Bundle bundle= getIntent().getExtras();
                clubid=bundle.getInt("clubid");
                intent.putExtra("clubid",clubid);
                startActivity(intent);

            }
        });

    }

    @Override
    View initViews(View view) {
        return null;
    }

    @Override
    void initEvents() {
        clubid = getIntent().getIntExtra("clubid",-1);
        clubName= getIntent().getStringExtra("clubname");
        club_name.setText(clubName);
    }

    @Override
    public void initData(){

        VideoModel videoModel = new VideoModel();
        videoModel.getvideolistByClubId(String.valueOf(clubid),this);

    }

    @Override
    public void onSuccess(Object object, int flag) {
        List<Video> Video   = (List<Video>)object;
        adapter = new VideoListAdapter(VideoListActivity.this,Video);
        LinearLayoutManager layoutManager = new LinearLayoutManager(VideoListActivity.this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        recyclerView.setItemAnimator(new DefaultItemAnimator());

    }

    @Override
    public void onFail() {

    }

    @Override
    public void onClick(View view) {

    }
}